<template>
  <FitScreen ref="largeScreen" :width="1920" :height="1080" mode="fit">
    <div class="bg-box">
      <slot name="bgBlock"></slot>
    </div>
    <div class="mask-view">
      <div class="top">
        <div class="top-left">
          <slot name="topBlock1"></slot>
        </div>
        <div class="top-middle">
          <div class="chongqing-title">全景数据展示</div>
        </div>
        <div class="top-right">
          <slot name="topBlock2"></slot>
        </div>
      </div>
    </div>
    <div class="cards-container-main">
      <div class="cards-container-top">
        <div class="cards-container-top-left">
          <div class="cards-container-top-left-card-1">
            <slot name="top-left-card-1"></slot>
          </div>
          <div class="cards-container-top-left-card-2">
            <slot name="top-left-card-2"></slot>
          </div>
        </div>
        <div class="cards-container-top-mid">
          <div class="cards-container-top-mid-card-1">
            <slot name="top-mid-card-1"></slot>
          </div>
          <div class="cards-container-top-mid-card-2">
            <slot name="top-mid-card-2"></slot>
          </div>
          <div class="cards-container-top-mid-card-3">
            <slot name="top-mid-card-3"></slot>
          </div>
        </div>
        <div class="cards-container-top-right">
          <div class="cards-container-top-right-card-1">
            <slot name="top-right-card-1"></slot>
          </div>
          <div class="cards-container-top-right-card-2">
            <slot name="top-right-card-2"></slot>
          </div>
        </div>
      </div>

      <div class="cards-container-bottom">
        <div class="cards-container-bottom-left">
          <slot name="bottom-left-card"></slot>
        </div>
        <div class="cards-container-bottom-right">
          <slot name="bottom-right-card"></slot>
        </div>
      </div>
    </div>
  </FitScreen>
</template>

<script>
export default {
  methods: {
    // 成功进入全屏模式时触发
    handleFullscreenChange(e) {
      if (
        !(
          document.fullscreenElement ||
          document.mozFullScreenElement ||
          document.webkitFullscreenElement ||
          document.msFullscreenElement
        )
      ) {
        this.go();
      }
      //   setTimeout(() => {
      //     if (
      //       !(
      //         document.fullscreenElement ||
      //         document.mozFullScreenElement ||
      //         document.webkitFullscreenElement ||
      //         document.msFullscreenElement
      //       )
      //     ) {
      //       this.go()
      //     }
      //   }, 300)
    },
    // 监听成功进入全屏模式事件
    openFullScreenListener() {
      this.openListenerFns.forEach((fn) => {
        document.addEventListener(fn, this.handleFullscreenChange);
      });
    },
    // 移除进入全屏模式事件
    removeOpenFullScreenListener() {
      this.openListenerFns.forEach((fn) => {
        document.removeEventListener(fn, this.handleFullscreenChange);
      });
    },
    // 进入全屏失败时触发
    handleFullscreenError() {
      this.go();
    },
    // 全屏失败事件监听
    failListener() {
      this.failListenerFns.forEach((fn) => {
        document.addEventListener(fn, this.handleFullscreenError);
      });
    },
    // 移除全屏失败事件监听
    removeFailListener() {
      this.failListenerFns.forEach((fn) => {
        document.removeEventListener(fn, this.handleFullscreenError);
      });
    },
    go() {
      this.$router.push("/statisticsQuery/realTimeCapture");
    },
  },
  mounted() {
    this.openListenerFns = [
      "fullscreenchange",
      "mozfullscreenchange",
      "webkitfullscreenchange",
      "msfullscreenchange",
    ];
    this.failListenerFns = [
      "fullscreenerror",
      "mozfullscreenerror",
      "webkitfullscreenerror",
      "msfullscreenerror",
    ];
    this.openFullScreenListener();
    this.failListener();
    const element = this.$refs.largeScreen.$el;
    /**
     * Element.requestFullscreen主要通过发出异步请求进行全屏
     * 1、如果被允许进入全屏，请求会返回resolve，同时触发fullscreenchange事件
     * 2、如果不允许进入全屏，请求会返回rejected，同时触发fullscreenerror事件
     */
    if (element.requestFullscreen) {
      element.requestFullscreen();
    } else if (element.mozRequestFullScreen) {
      // 兼容Firefox
      element.mozRequestFullScreen();
    } else if (element.webkitRequestFullscreen) {
      // 兼容Chrome、Safari和Opera
      element.webkitRequestFullscreen();
    } else if (element.msRequestFullscreen) {
      // 兼容IE/Edge
      element.msRequestFullscreen();
    }
  },
};
</script>

<style scoped lang="scss">
/** 上 */
// 上边固定高
$topBlockHeight: 67px;
// 上左区域宽
$topLeftWidth: 24%;
// 上中区域宽
$topMiddleWidth: 29%;
// 上右区域宽
$topRightWidth: 47%;
// 上 左右上边距
$topLeftMarginTop: 15px;
// 上 左右高度
$topLeftHeight: calc(100% - $topLeftMarginTop);
// 左右边距
$leftRightMargin: 40px;
// 左右内边距
$leftRightPadding: 30px;
// 下边距
$bottomMargin: 40px;
// 上下内边距
$topBottomPadding: 40px;

/** 下 */
// 下边固定高度
$bottomBlockHeight: calc(100vh - $topBlockHeight - $bottomMargin);
// 下左侧区域宽
$bottomLeftWidth: 30%;
// 中间区域宽
$bottomMiddleWidth: 40%;
// 右侧区域宽
$bottomRightWidth: 30%;
// 公共边距
$commonMargin: 40px;
// 下 左上高度
$leftTopBlockHeight: 30%;
// 下 左下高度
$leftBottomBlockHeight: calc(70% - $commonMargin);
// 下 中高度
$leftMiddleBlockHeight: calc(100% - $commonMargin);
// 下 右上高度
$rightTopBlockHeight: 48%;
// 下 右下高度
$rightBottomBlockHeight: calc(52% - $commonMargin);

$borderColor: #194871;
$borderWidth: 2px;

.chongqing-layout {
  // background-image: url("/public/panoramicData/chongqing_bg.png");
  background-position-x: center;
  background-repeat: no-repeat;
  background-size: cover;
  background-color: #030d18;
  height: 100%;
  width: 100%;
  overflow: hidden;
  position: relative;

  .bg-box {
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
  }

  .mask-view {
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    // z-index: 0;
  }

  &.debug {
    & > div {
      border: 1px solid red;

      & > div {
        border: 1px solid red;
      }
    }
  }
}

.top {
  height: $topBlockHeight;
  // margin: 0 $leftRightMargin;
  display: flex;
  align-items: center;
  // background: rgba(3, 10, 14, 0.7);
  background-image: url("/public/panoramicData/Rectangle2.png");
  background-position-x: center;
  background-repeat: no-repeat;
  background-size: cover;
  position: relative;
  z-index: 3;

  .top-left {
    width: $topLeftWidth;
    height: $topLeftHeight;
    margin-top: $topLeftMarginTop;
    padding-left: $leftRightPadding;
    // border-top: $borderWidth solid $borderColor;
    // border-right: $borderWidth solid $borderColor;
  }

  .top-middle {
    width: $topMiddleWidth;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 3;

    // border-bottom: $borderWidth solid $borderColor;
    .chongqing-title {
      text-align: center;
      letter-spacing: 0px;
      font-size: 42px;
      color: #e49d19;
      font-weight: normal;
      font-family: "YouSheBiaoTiHei";
      background-clip: text;
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
      color: transparent;
      background-image: linear-gradient(0deg, #1dd4ff 8%, #ffffff 99%);
      position: relative;
      z-index: 3;
    }
  }

  .top-right {
    width: $topRightWidth;
    height: $topLeftHeight;
    margin-top: $topLeftMarginTop;
    // border-top: $borderWidth solid $borderColor;
    // border-left: $borderWidth solid $borderColor;
    padding-right: $leftRightPadding;
  }
}

.cards-container {
  &-main {
    width: 100%;
    height: calc(100% - 70px);
    margin-top: 10px;
  }

  &-top {
    height: 660px;
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;

    &-left {
      height: 100%;
      width: 448px;
      overflow: auto;

      &-card-1 {
        margin: 10px;
        height: 310px;
        width: 428px;
        position: relative;
        z-index: 10;
        overflow: auto;
      }

      &-card-2 {
        margin: 20px 10px 10px;
        height: 310px;
        width: 428px;
        position: relative;
        z-index: 10;
        overflow: auto;
      }
    }

    &-mid {
      width: calc(100% - 900px);
      height: calc(100% - 20px);
      margin-top: 10px;
      display: flex;
      flex-wrap: wrap;
      justify-content: center;

      &-card-1,
      &-card-2,
      &-card-3 {
        width: 280px;
        height: 150px;
        position: relative;
        z-index: 10;
      }

      &-card-2 {
        margin: 0px 10px;
      }
    }

    &-right {
      height: calc(100% + 40px);
      width: 448px;
      overflow: auto;

      &-card-1 {
        margin: 10px;
        height: 310px;
        width: 428px;
        position: relative;
        z-index: 10;
        overflow: auto;
      }

      &-card-2 {
        margin: 20px 10px 10px;
        height: 352px;
        width: 428px;
        position: relative;
        z-index: 10;
        overflow: auto;
      }
    }
  }

  &-bottom {
    height: 330px;
    width: 100%;
    display: flex;
    &-left {
      margin: 10px;
      height: 310px;
      width: 428px;
      position: relative;
      z-index: 10;
      overflow: auto;
    }
    &-right {
      height: 310px;
      width: calc(100% - 470px);
      position: relative;
      z-index: 10;
      margin-left: 10px;
      margin-top: 10px;
    }
  }
}

.left-top-Block {
  height: $leftTopBlockHeight;
  min-height: 240px;
}

.left-bottom-Block {
  height: $leftBottomBlockHeight;
  min-height: 380px;
}

.right-top-Block {
  height: $rightTopBlockHeight;
  min-height: 293px;
}

.right-bottom-Block {
  height: $rightBottomBlockHeight;
  min-height: 296px;
}
</style>
